package org.dbview.controller;

import java.util.List;
import java.util.Map;

import org.dbview.model.Page;
import org.dbview.model.SimpleResponse;
import org.dbview.model.ViewDictionary;
import org.dbview.model.ViewdictPageItem;
import org.dbview.service.IViewDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ViewDictionaryController {
	
	@Autowired
	private IViewDictionaryService viewDictionaryService;
	

	@RequestMapping(value = "getViewList.do")
	@ResponseBody
	public ViewdictPageItem getViewList(@RequestBody ViewdictPageItem viewdictPageItem) {
		if (viewdictPageItem.getPage() == null) {
			Page page = new Page(0, 20);
			viewdictPageItem.setPage(page);
		}
		if ("全部".equals(viewdictPageItem.getModuleName())) {
			viewdictPageItem.setModuleName(null);
		}
		if ("全部".equals(viewdictPageItem.getTableName())) {
			viewdictPageItem.setTableName(null);
		}
		return viewDictionaryService.getViewByModuleAndTable(viewdictPageItem);
	}
	
	@RequestMapping(value = "getTableColumn.do")
	@ResponseBody
	public List<ViewDictionary> getTableColumn(@RequestBody String tableName) {
		if (tableName != null && !"".equals(tableName)) {
			return viewDictionaryService.getColumnByTable(tableName);
		} else {
			return null;
		}
	}
}
